<?php /*a:2:{s:58:"E:\wamp64\www\tp5\miqicms\app\admin\view\doc_con\edit.html";i:1667608765;s:57:"E:\wamp64\www\tp5\miqicms\app\admin\view\public\base.html";i:1667268361;}*/ ?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
 <title>title2233</title>
    <link rel="stylesheet" type="text/css" href="http://127.0.0.1:8000/static/admin/static/css/style.css" />
    <link rel="stylesheet" type="text/css" href="http://127.0.0.1:8000/static/admin/layui/css/layui.css" />
</head>
    <style type="text/css">
      .layui-laypage li {float:left !important;}
    </style>
<script>
  var Oper = {
    submit_yes : true,
    layui : false,
    layer : false,
    jq : false,
    form : false,
    element : false,
    table : false,
    key : 'id',
    //一些按钮的事件绑定
    config : {
      //开关
      'switch' : 'switch(status)',
      //添加
      'add' : {
        'element' : '#btn-add',
        'name' : '添加',
        'width' : '600px',
        'height' : '460px',
        'method' : 'add',
      },
      //编辑
      'edit' : {
        'element' : 'tbody#userList tr td #edit',
        'width' : '600px',
        'height' : '520px',
      },
    //编辑
    // 'edit' : {
    //     'element' : '.plugin_edit',
    //     'width' : '600px',
    //     'height' : '520px',
    // },
      //删除
      'delete' : {
        'element' : 'tbody#userList tr td #delete',
        'all' : '#btn-alldel',
        'method' : 'delete',
      },
    },
    set : function(layui, name, module, key) {
      var self = this;
      self.layui = layui;
      self.layer = layui.layer;
      self.jq = layui.jquery;
      self.form = layui.form;
      self.element = layui.element;
      self.table = layui.table;
      self.name = name;
      self.module = module;
      self.checked = [];
      self.key = key;
    }

    //列表页
    ,initList : function(layui, name, module, key) {
      var self = this;
      self.set(layui, name, module, key);

      self.jq(function() {
        self.switch();
        self.add();
        self.edit();
        self.delete();
        self.checkall();
      });
    }

    //更新页 暂未实现
    ,initUpdate : function(layui, name, form_id, update_url, list_url, editor, tag) {
      var self = this;
      self.set(layui, name, false, false);
      self.jq(function() {
        self.tag(tag);
        self.editor(editor);
        self.submit(form_id, update_url, list_url, editor);
      });
    }

    ,remove : function(a, v) {
      for (var i = 0; i < a.length; i++) {
        if (a[i] == v) a.splice(i, 1);
      }
      return -1;
    }

    ,msg : function(msg, option, func) {
      if (!option) {
        option = {
          time:1800
        };
      }
      if (func == 'reload') {
        func = function() {
          location.reload();
        }
      } else {
        func = false;
      }
      this.layer.msg(msg, option, func);
    }

    ,switch : function() {
      var self = this;
      self.form.on(self.config.switch, function(data) {
        var url = self.jq(this).attr('data-uri');
        var val = '';
        if (data.elem.checked == true) {
          val = 1;
        } else {
          val = 0;
        }

        self.jq.post(url + "&val=" + val, data.field, function(res) {
          if (res.status ==  1) {
            self.msg('更新成功');
          } else {
            self.msg('更新失败');
          }
        });
      });
    }

    // //初始化标签
    ,tag : function(tag) {
      //自动获取标签
      if (!tag) {
        return;
      }
      var self = this;
      self.jq(tag).on('click', function() {
        var title = self.jq.trim(self.jq('#J_title').val());
        if(title == ''){
          layer.msg('请先填写标题',{time:1800});
          return false;
        }
        self.jq.getJSON('', {title:title}, function(result){
          if(result.status == 1){
            self.jq('#tpt_input').val(result.data);
          }else{
            self.layer.msg('获取失败',{time:1800});
          }
        });
      });
    }

    // //初始化编辑器
    ,editor : function(editor)
    {
      if (!editor) {
        return;
      }
      var self = this;
      self.editors = {};
      for (var i in editor) {
        //编辑器图片上传
        self.layui.layedit.set({
          uploadImage: {
            url: '<?php echo url("attachment/editer_upload"); ?>',
            type: 'post'
          }
        });
        //构建一个默认的编辑器
        self.editors[editor[i]] = self.layui.layedit.build(editor[i]);
      }
    }

    // //提交按钮
    ,submit : function(form_id, update_url, list_url, editor) {
      var self = this;
      var loading = false;

      self.layui.form.on('submit('+form_id+')', function(data){
        if (self.submit_yes == false) {
          return false;
        }
        self.submit_yes = false;
        if (list_url) {
          loading = self.layer.load(2, {shade: [0.2,'#000']});
        }
        if (editor) {
          for (var i in editor) {
            data.field[editor[i]] = self.layui.layedit.getContent(self.editors[editor[i]]);
          }
        }
        var url = "";
        var temp = update_url.split('/');
        var post_url = url.replace('module', temp[0]);
        post_url = post_url.replace('method', temp[1]);
        self.jq.post(post_url,data.field,function(data){
          if(data.status ==  1){
            if (list_url) {
              if (loading) {
                self.layer.close(loading);
              }
              self.layer.msg(data.msg,{time:1800},function(){
                var temp = list_url.split('/');
                list_url = url.replace('module', temp[0]);
                list_url = list_url.replace('method', temp[1]);
                self.submit_yes = true;
                location.href = list_url;
              });
            } else {
              self.layer.msg(data.msg,{time:1800},function(){
                self.submit_yes = true;
                //关闭弹层后刷新父页面
                window.parent.location.reload();
                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
              });
            }
          }else{
            self.submit_yes = true;
            if (list_url) {
              self.layer.msg(data.msg,{time:1800});
              if (loading) {
                self.layer.close(loading);
              }
              return false;
            } else {
              self.layer.msg(data.msg,{time:1800});
              return false;
            }
          }
        });
        return false;
      });
    }

    //添加
    ,add : function() {
      var self = this;
      this.jq(self.config.add.element).click(function() {
        var url = "<?php echo url('module/method'); ?>";
        url = url.replace('module', self.module);
        url = url.replace('method', self.config.add.method);
        self.layer.open({
          type: 2,
          title: self.config.add.name + self.name,
          area: [self.config.add.width, self.config.add.height],
          fixed: true,
          maxmin: true,
          content: url
        });
      });
    }

    //编辑
    ,edit : function() {
      var self = this;
      self.jq(self.config.edit.element).click(function() {
        var title   = self.jq(this).attr('data-title');
        var url   = self.jq(this).attr('data-uri');
        self.layer.open({
          type: 2,
          title: title,
          area: [self.config.edit.width, self.config.edit.height],
          fixed: true,
          maxmin: true,
          content: url
        });
      });
    }


    //全选
    ,checkall : function() {
      var self = this;
      self.form.on('checkbox(allChoose)', function(data) {
        var child = self.jq(data.elem).parents('table').find('.doc_checkbox');

        child.each(function(index, item) {
          item.checked = data.elem.checked;
          if (item.checked) {
            self.checked.push(self.jq(this).val());
          } else {
            self.remove(self.checked, self.jq(this).val());
          }
        });
        self.form.render('checkbox');
      });
      self.form.on('checkbox(itemChoose)',function(data) {
        if (data.elem.checked) {
          self.checked.push(self.jq(this).val());
        } else {
          self.remove(self.checked, self.jq(this).val());
        }
      });
    }

    //删除
    ,delete : function() {
      var self = this;
      self.jq(self.config.delete.element).click(function(data) {
        var id  = self.jq(this).attr('data-id');
        var url = self.jq(this).attr('data-uri');
        self.deleteAction(url);
      });

      self.deleteAll();
    }

    //批量删除
    ,deleteAll : function() {
      var self = this;
      if (this.jq(self.config.delete.all).length) {
        this.jq(self.config.delete.all).click(function(data) {
          if (!self.checked || self.checked.length <= 0) {
            self.msg('请选择需要删除的数据');
          } else {
            var url = "<?php echo url('module/method', array('me' => 1)); ?>";
            url = url.replace('module', self.module);
            url = url.replace('method', self.config.delete.method);
            var url = url + "&"+self.key+"=" + self.checked.join(',');
            self.deleteAction(url);
          }
        });
      }
    }

    //确认删除
    ,deleteAction : function(url, param) {
      if (!param) {
        param = {};
      }
      var self = this;
      self.layer.confirm('删除'+self.name+'将不能恢复，确认删除吗？'
              , {btn: ['确认','取消']}
              , function() {
                self.jq.post(url, param, function(res) {
                  if(res.status ==  1) {
                    self.msg(res.msg, false, 'reload');
                  } else {
                    self.msg(res.msg);
                    return false;
                  }
                });
              }
              , function() {
                self.msg('取消删除');
                return false;
              }
      );
      return false;
    }
  };
</script>
<script type="text/javascript" src="http://127.0.0.1:8000/static/admin/layui/layui.js"></script>
<body class="body">


<!--编辑菜单-->
<form class="layui-form layui-form-pane" action="" style="padding:20px;">
  <input type="hidden" name="id" value="<?php echo htmlentities((isset($info['id']) && ($info['id'] !== '')?$info['id']:'')); ?>" />
  <div class="layui-form-item">
    <label class="layui-form-label">文件上传</label>
    <div class="layui-input-block">
      <button type="button" class="layui-btn" id="firstID">
        <i class="layui-icon">&#xe67c;</i>上传按钮
      </button>
      <input type="hidden" name="convert_status" id="convert_status" class="layui-input" value="<?php echo htmlentities((isset($info['convert_status']) && ($info['convert_status'] !== '')?$info['convert_status']:'1')); ?>">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">文档标题</label>
    <div class="layui-input-block">
      <input type="text" name="title" id="title" placeholder="请输入" class="layui-input" value="<?php echo htmlentities((isset($info['title']) && ($info['title'] !== '')?$info['title']:'')); ?>">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">文档分类</label>
    <div class="layui-input-block">
      <select name="cid" lay-verify=“required|number”>
        <option value=""></option>
        <?php if(is_array($catelist) || $catelist instanceof \think\Collection || $catelist instanceof \think\Paginator): $i = 0; $__LIST__ = $catelist;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$val): $mod = ($i % 2 );++$i;?>
          <option disabled="disabled" value="<?php echo htmlentities($val['id']); ?>" <?php if((isset($info['cid']) && ($info['cid'] !== '')?$info['cid']:'') == $val['id']): ?>selected="selected"<?php endif; ?>><?php echo htmlentities($val['name']); ?></option>
        <?php if(is_array($val['erji']) || $val['erji'] instanceof \think\Collection || $val['erji'] instanceof \think\Paginator): $i = 0; $__LIST__ = $val['erji'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
            <option value="<?php echo htmlentities($vo['id']); ?>" <?php if((isset($info['cid']) && ($info['cid'] !== '')?$info['cid']:'') == $vo['id']): ?>selected="selected"<?php endif; ?>>&nbsp;&nbsp;&nbsp;├─ <?php echo htmlentities($vo['name']); ?></option>
        <?php endforeach; endif; else: echo "" ;endif; ?>
        <?php endforeach; endif; else: echo "" ;endif; ?>
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">文档专辑</label>
    <div class="layui-input-block">
      <select name="zjid" >
        <option value=""></option>
        <?php if(is_array($zjlist) || $zjlist instanceof \think\Collection || $zjlist instanceof \think\Paginator): $i = 0; $__LIST__ = $zjlist;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$val): $mod = ($i % 2 );++$i;?>
          <option value="<?php echo htmlentities($val['id']); ?>" <?php if((isset($info['zjid']) && ($info['zjid'] !== '')?$info['zjid']:'') == $val['id']): ?>selected="selected"<?php endif; ?>><?php echo htmlentities($val['title']); ?></option>
        <?php endforeach; endif; else: echo "" ;endif; ?>
      </select>
    </div>
  </div>


  <div class="layui-form-item">
    <label class="layui-form-label">文档简介</label>
    <div class="layui-input-block">
      <textarea name="intro" id="intro" class="layui-textarea"><?php echo htmlentities((isset($info['intro']) && ($info['intro'] !== '')?$info['intro']:'')); ?></textarea>
    </div>
  </div>

  <div class="layui-form-item" >
    <label class="layui-form-label" >文档积分</label>
    <div class="layui-input-block">
      <input type="number" name="score" id="score" class="layui-input" value="<?php echo htmlentities((isset($info['score']) && ($info['score'] !== '')?$info['score']:'0')); ?>">
    </div>
  </div>

  <div class="layui-form-item" >
    <label class="layui-form-label">状态</label>
    <div class="layui-input-block">
      <input type="radio" title="未审核" name="status" value="0" <?php if((isset($info['status']) && ($info['status'] !== '')?$info['status']:'0') == '0'): ?>checked="checked"<?php endif; ?>>
      <input type="radio" title="已审核" name="status" value="1" <?php if((isset($info['status']) && ($info['status'] !== '')?$info['status']:'') == '1'): ?>checked="checked"<?php endif; ?>>


    </div>
  </div>
  <div class="layui-form-item" >
    <label class="layui-form-label">精品推荐</label>
    <div class="layui-input-block">
      <input type="radio" title="是" name="choice" value="1" <?php if((isset($info['choice']) && ($info['choice'] !== '')?$info['choice']:'1') == '1'): ?>checked="checked"<?php endif; ?>>
      <input type="radio" title="否" name="choice" value="0" <?php if((isset($info['choice']) && ($info['choice'] !== '')?$info['choice']:'0') == '0'): ?>checked="checked"<?php endif; ?>>
    </div>
  </div>
  <div class="layui-form-item" >
    <label class="layui-form-label">置顶</label>
    <div class="layui-input-block">
      <input type="radio" title="是" name="top" value="1" <?php if((isset($info['top']) && ($info['top'] !== '')?$info['top']:'1') == '1'): ?>checked="checked"<?php endif; ?>>
      <input type="radio" title="否" name="top" value="0" <?php if((isset($info['top']) && ($info['top'] !== '')?$info['top']:'0') == '0'): ?>checked="checked"<?php endif; ?>>
    </div>
  </div>
  <input type="hidden" name="fileurl"  id="fileurl"  size="30" value="<?php echo htmlentities((isset($info['fileurl']) && ($info['fileurl'] !== '')?$info['fileurl']:'')); ?>">
  <input type="hidden" name="ext"  id="ext"  size="30" value="<?php echo htmlentities((isset($info['ext']) && ($info['ext'] !== '')?$info['ext']:'')); ?>">
  <input type="hidden" name="filesize"  id="filesize"  size="30" value="<?php echo htmlentities((isset($info['filesize']) && ($info['filesize'] !== '')?$info['filesize']:'')); ?>">
  <input type="hidden" name="oldname"  id="oldname"  size="30" value="<?php echo htmlentities((isset($info['oldname']) && ($info['oldname'] !== '')?$info['oldname']:'')); ?>">
  <input type="hidden" name="hash"  id="hash"  size="30" value="<?php echo htmlentities((isset($info['hash']) && ($info['hash'] !== '')?$info['hash']:'')); ?>">
  <input type="hidden" name="viewurl"  id="viewurl"  size="30" value="<?php echo htmlentities((isset($info['viewurl']) && ($info['viewurl'] !== '')?$info['viewurl']:'')); ?>">
  <input type="hidden" name="convert_key"  id="convert_key"  size="30" value="<?php echo htmlentities((isset($info['convert_key']) && ($info['convert_key'] !== '')?$info['convert_key']:'')); ?>">
  <input type="hidden" name="tags" id="tags"  value="<?php echo htmlentities((isset($info['tags']) && ($info['tags'] !== '')?$info['tags']:'')); ?>" >

  <div class="layui-form-item">
    <label class=""></label>
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit="" lay-filter="content_edit">提交保存</button>
    </div>
  </div>
</form>



<script>
  //Demo
  layui.use(['layer','jquery','form','element','upload'], function () {
    // 操作对象
    var layer = layui.layer,$ = layui.jquery,form = layui.form, element = layui.element,upload = layui.upload;

    // 提交
    Oper.initUpdate(layui, '文档分类', 'content_edit', 'doc_con/edit');

    //上传图片
    upload.render({
      elem: '#firstID', 			//选中你要绑定的上传组件
      url: "<?php echo url('doc_con/ajax_upload'); ?>",//上传接口
      accept:'file',					//文件类型，不写默认是images，file表示全类型
      done: function(data){		//上传完回调，这里的res必须是json类型
        if (data.status === 1) {
          layer.msg(data.msg, {icon: 1});
          $('#fileurl').val(data.info.name);
          $('#oldname').val(data.info.oldname);
          $('#title').val(data.info.oldname);
          $('#filesize').val(data.info.size);
          $('#viewurl').val(data.info.name);
          $('#hash').val(data.info.hash);
          $('#tags').val(data.info.ext);
          $('#ext').val(data.info.ext);
          $('#convert_key').val(data.info.convert_key);
        }else{
          layer.msg('上传失败', {icon: 2});
        }
      },
      error: function(){
        layer.msg('error'+ res.status, {icon: 2});
      }
    });
  });
</script>

</body>
</html>